package 力扣;

import java.util.ArrayList;
import java.util.List;

/**
 * @author yyq
 * @create 2022-05-17 16:15
 */
public class leetcode78 {
    List<List<Integer>> lists = new ArrayList<>();
    List<Integer> list = new ArrayList<>();
    public List<List<Integer>> subsets(int[] nums) {
        int startIndex = 0;
        backTracking(startIndex,lists,list,nums);
        return  lists;
    }

    private void backTracking(int startIndex, List<List<Integer>> lists, List<Integer> list,  int[] nums) {
        if(list.size()==nums.length){
            lists.add(new ArrayList<>(list));
            return;
        }else lists.add(new ArrayList<>(list));

        for (int i = startIndex; i < nums.length; i++) {
            list.add(nums[i]);
            backTracking(i + 1, lists,list,nums);
            list.remove(list.size()-1);
        }
    }
}
